<template>
	<view>
		  <view class="cartList" v-for="(item,index) in cartList">
			  <view>
				  {{item.title}}
			  </view>
			  
			  <view>
				  	<u-number-box v-model="item.num" @change="valChange($event,index,item.id)"></u-number-box>
			  </view>
		  </view>
	</view>
</template>

<script>
	// /cart/get_cart
	
	import {get_cart as get_cart_api,update_num} from '@/api/shop.js'
	export default {
		data() {
			return {
				cartList:[]
			}
		},
		onLoad() {
			  this.get_cart()
		},
		methods: {
			get_cart(){
				get_cart_api().then(res=>{
					
					console.log(res)
					
					this.cartList = res.data;
				})
			},
			valChange(e,i,id){
				console.log(e)
				console.log(i)
				
				let {value } = e;
				let {cartList} = this;
				let type = 0;
				
				
				
				if(value<cartList[i].num){
					type = 1;
				}
				
				update_num({
					id,
					type
				}).then(res=>{
					
					console.log(res)
				})
			}
		}
	}
</script>

<style>

</style>
